package com.prezs.service.serviceImpl;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.prezs.entity.Article;
import com.prezs.mapper.ArticleMapper;
import com.prezs.service.IArticleService;

public class ArticleServiceImpl implements IArticleService {

	private SqlSessionFactory sqlSessionFactory;

	// 创建一个构造器，方便注入工厂
	public ArticleServiceImpl(SqlSessionFactory factory) {
		this.sqlSessionFactory = factory;
	}

	/**
	 * 添加文章
	 * 
	 */
	public void addArticle(Article article) {
		// 通过工厂获取SqlSession对象
		SqlSession session = sqlSessionFactory.openSession();
		// 调用该对象的插入方法
		// session.insert("com.prezs.mapper.ArticleMapper.addArticle", article);
		ArticleMapper mapper = session.getMapper(ArticleMapper.class);
		mapper.addArticle(article);
		// 3.提交事务
		session.commit();
		// 释放资源
		session.close();
	}

}
